<?php
	require("/export/www/transportation/includes/variables.php");
	$sql = sprintf("SELECT `t_sched_groups`.`description` as group_desc, `t_sched_main`.`description` as day_desc, `t_sched_main`.`week`, `t_sched_structure`.`description` as line_desc, `t_sched_shifts`.* FROM `t_sched_groups`, `t_sched_main`, `t_sched_structure`, `t_sched_shifts`, `t_sched_date_relator`
					WHERE `t_sched_groups`.`group_id` = `t_sched_main`.`group_id`
					AND `t_sched_main`.`table_id` = `t_sched_structure`.`table_id`
					AND `t_sched_structure`.`structure_id` = `t_sched_shifts`.`structure_id`
					AND `t_sched_shifts`.`shift_id` = %s
					AND `t_sched_date_relator`.`main_id` = `t_sched_main`.`table_id`
					LIMIT 1", 
					 quote_smart($_GET['shift']));
	$result = mysql_query($sql);
	//error check for results
	$row = mysql_fetch_assoc($result);
	$vSummary = $row['line_desc'] . ' from ' . formattedTime($row['shift_start']) . ' to ' . formattedTime($row['shift_end']) . '.';
	$vStart = $row['date'] . "T" . $row['shift_start'] . '00';
	$vEnd = $row['date'] . "T" . $row['shift_end'] . '00';
    $Filename = "UCTS_shift" . $_GET['shift'] . ".vcs";
    header("Content-Type: text/x-vCalendar");
    header("Content-Disposition: inline; filename=$Filename");	
?>
BEGIN:VCALENDAR
VERSION:1.0
PRODID:Transportation System
BEGIN:VEVENT
SUMMARY:<?= $vSummary ?>
DESCRIPTION;ENCODING=QUOTED-PRINTABLE: <?= $DescDump ?>
DTSTART:<?= $vStart ?>
DTEND:<?= $vEnd ?>
END:VEVENT
END:VCALENDAR
<?php
	function formattedTime($time) {
		$hour = substr($time,0,2);
		$min = substr($time,2,2);
		return $hour . ':' . $min;
	}
?>